import {
  // 创建路由的api
  createRouter,
  // 创建路由的历史模式
  createWebHistory,
} from 'vue-router'

import { useUserInfoStore } from '@/store/userinfo.js'

const routes = [
  {
    path: '/',
    redirect: '/menu',
  },
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/login/index.vue'),
  },
  {
    name: 'menu',
    path: '/menu',
    component: () => import('@/views/menu/index.vue'),
    children: [
      {
        path: '/home',
        name: 'home',
        meta: { title: '首页', icon: 'House' },
        component: () => import('@/views/home/index.vue'),
      },
      {
        path: '/set',
        name: 'set',
        meta: { title: '系统设置', icon: 'Tools' },
        component: () => import('@/views/set/index.vue'),
      },
      {
        path: '/overview',
        name: 'overview',
        meta: { title: '系统概览', icon: 'Document' },
        component: () => import('@/views/overview/index.vue'),
      },
      {
        path: '/message_manage',
        name: 'message_manage',
        meta: { title: '消息管理员', icon: 'Tools' },
        component: () => import('@/views/user_manage/message_manage/index.vue'),
      },
      {
        path: '/product_manage',
        name: 'product_manage',
        meta: { title: '产品管理员', icon: 'Tools' },
        component: () => import('@/views/user_manage/product_manage/index.vue'),
      },
      {
        path: '/request_module',
        name: 'request_module',
        meta: { title: '请求中断模块', icon: 'Tools' },
        component: () => import('@/views/request_module/index.vue'),
      },
      {
        path: '/chatgpt_typing_effect',
        name: 'chatgpt_typing_effect',
        meta: { title: 'SSE模块', icon: 'Tools' },
        component: () => import('@/views/chatgpt_typing_effect/index.vue'),
      },
      {
        path: '/Virtual_list',
        name: 'Virtual_list',
        meta: { title: '虚拟列表渲染十万条数据', icon: 'Tools' },
        component: () => import('@/views/Virtual_list/index.vue'),
      },
      {
        path: '/officeView',
        name: 'officeView',
        meta: { title: 'office文件预览微软服务', icon: 'Tools' },
        component: () => import('@/views/officeView/index.vue'),
      },
      {
        path: '/pdfOverview',
        name: 'pdfOverview',
        meta: { title: 'pdf预览', icon: 'Tools' },
        component: () => import('@/views/pdfOverview/index.vue'),
      },
      {
        path: '/drag',
        name: 'drag',
        meta: { title: 'drag 拖拽效果 ', icon: 'Tools' },
        component: () => import('@/views/drag/index.vue'),
      },
      {
        path: '/Uploadlargefiles',
        name: 'Uploadlargefiles',
        meta: { title: '大文件上传', icon: 'Tools' },
        component: () => import('@/views/Uploadlargefiles/index.vue'),
      },
      //文件上传
      {
        path: '/ExcelFile',
        name: 'ExcelFile',
        redirect: '/single',
        meta: { title: '文件上传', icon: 'Tools' },

        children: [
          {
            path: '/single',
            name: 'single',
            meta: { title: '单文件上传' },
            component: () => import('@/views/Uploadlargefiles/single.vue'),
          },
          {
            path: '/multiple',
            name: 'multiple',
            meta: { title: '多文件上传' },
            component: () => import('@/views/Uploadlargefiles/multiple.vue'),
          },
          {
            path: '/large',
            name: 'large',
            meta: { title: '大文件上传' },
            component: () => import('@/views/Uploadlargefiles/large.vue'),
          },
        ],
      },
      {
        path: '/excel',
        name: 'excel',
        meta: { title: 'excel的导入导出', icon: 'Tools' },
        component: () => import('@/views/ExportImportExcel/index.vue'),
      },
    ],
  },
]
const addroutesList = [
  {
    path: '/doctor',
    name: 'doctor',
    meta: { title: '权限医生界面' },
    component: () => import('@/views/testIdentity/doctorIdentity.vue'),
  },
  {
    path: '/product',
    name: 'product',
    meta: { title: '产品经理权限界面' },
    component: () => import('@/views/testIdentity/productIdentity.vue'),
  },
  {
    path: '/user',
    name: 'user',
    meta: { title: '用户权限界面' },
    component: () => import('@/views/testIdentity/userIdentity.vue'),
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, from) => {
  const userInfoStore = useUserInfoStore()
  if (!userInfoStore.userInfo.identity) {
    useUserInfoStore.getUserInfo(userInfoStore.userInfo.id)
  }
})
export default router
